package serv;

import javax.servlet.annotation.WebServlet; 

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author Administrator
 *
 */

@WebServlet(description = "支付令servlet", urlPatterns = { "/Pay" })
public class Pay extends HttpServlet {
	private static final long serialVersionUID = 1L;
	String m_op = null;
	Vector<Vector<String>> vt = new Vector<Vector<String>>();
	Vector<Vector<String>> vt_organ = new Vector<Vector<String>>();
	String m_user = "";
	String m_organ = "";
    

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Pay() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@SuppressWarnings("unchecked")
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int ret=-1;
		vt.clear();
		request.setCharacterEncoding("GBK");
		response.setContentType("text/html");
		response.setCharacterEncoding("GBK");
		PrintWriter out = response.getWriter();
		//以下为DEBUG
//		out.println("type:"+request.getParameter("type"));
//		out.println("op:"+request.getParameter("op"));
//		out.println("bank_level:"+request.getParameter("bank_level"));
//		return;
		try {
			String m_type = request.getParameter("type");
			if(m_type==null){
				String s = "参数错误 —— type=" + m_type;
				throw(new ServletException(s));
			}
			m_op = request.getParameter("op");
			
			//debug
			System.out.println("type:"+m_type);
			System.out.println("m_op:"+m_op);

			HttpSession session = request.getSession(true);
			m_user = (String)session.getAttribute("user_name");
		    GwkOrgan Organ = (GwkOrgan)session.getAttribute("logonOrgan");
		    m_organ = Organ.getM_BANK_ORGAN_ID();
		    vt_organ = Organ.m_organ;
			//session.setMaxInactiveInterval(20);
			if(session.getAttribute(m_type.toString())!=null){
				vt = (Vector<Vector<String>>) session.getAttribute(m_type.toString());
				System.out.println("vt size: " + vt.size());
			}
			
			if (m_type.compareTo("pay_tmp") == 0) {
				ret = do_pay_tmp(request, response);
				if(ret == -10){
					out.println("新增支付令出错，支付令已录入或已执行过支付");
					out.println("<p><a href=\"javascript:history.go(-1);\">返回</a></p>");
					return;
				}
			}else if (m_type.compareTo("pay_bill") == 0) {
				ret = do_pay_bill(0,request, response);
			}else if (m_type.compareTo("pay_billb") == 0) {
				ret = do_pay_bill(1,request, response);
			}else if (m_type.compareTo("bank_unit") == 0) {
				ret = do_bank_unit(request, response);
			}else if (m_type.compareTo("payno") == 0) {
				vt = (Vector<Vector<String>>) session.getAttribute("pay_tmp");
				System.out.println("do_payno vt size: " + vt.size());
				do_payno(request, response);
				out.println("<p><a href='User/Pay.jsp'>返回支付录入</a></p>");
				return;
			}else{
				out.println("参数错误 —— type=" + m_type);
				return;
			}

			if (ret == 0) {
				if(vt.size()>=0)
					session.setAttribute(m_type.toString(), vt.clone());
				else
					session.removeAttribute(m_type.toString());
			}
			String nextJSP = null;
			if (m_type.compareTo("bank_unit") == 0) {
				nextJSP = "User/BaseBankUnit.jsp";
			}else if (m_type.compareTo("pay_bill") == 0) {
				nextJSP = "User/Pay_paybill.jsp";
			}else if (m_type.compareTo("pay_billb") == 0) {
				nextJSP = "User/Pay_paybillb.jsp";
			}else
				nextJSP = "User/Pay.jsp";
			if(ret==0)
				response.sendRedirect(nextJSP);
			else{
				out.println("<p>操作失败,请检查</p>");
				out.println("<p><a href='javascript:history.go(-1);'>返回</a></p>");
			}
			/*ServletContext sc = getServletContext();
			RequestDispatcher rd = null;
			rd = sc.getRequestDispatcher("/"+nextJSP); //定向的页面
			rd.forward(request, response);
			*/
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace(out);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}
	
	//支付令录入pay_tmp 
private int do_pay_tmp(HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException{
		String mysql = null;
		int choice=0;
		int ret;
		String inseq = "";
		String bankno = null;
		
		if(request.getParameter("choice")!=null){
			choice = Integer.valueOf(request.getParameter("choice"));
		}

		GwkDB gwkdb = new GwkDB();

		if(m_op==null){
			//空时
			return -1;
		}else if(m_op.compareTo("Q") == 0){
			mysql = "select a.bankno,a.officeno,a.tellerno,a.payno,a.checkno,a.upd_user," +
					"to_char(a.upd_date,'yyyy/mm/dd hh24:mi:ss'),a.trans_seqno " + 
					"from gx_corp_payno_tmp a,gx_corp_usr b ";
			mysql += "where a.upd_user = b.usr_id ";
			mysql += "and b.bank_organ_id='" + m_organ +"' ";
			/*mysql += "and b.bank_organ_id in (";
			for (int j = 0; j < vt_organ.size(); j++) {
				if (j == 0) {
					mysql += "'";
				} else
					mysql += ",'";
				mysql += vt_organ.get(j).get(0).toString() + "'";
			}
			mysql += ") ";*/
		}else if(m_op.compareTo("A") == 0){
			//增加
			bankno = request.getParameter( "gx_corp_payno_tmp.bankno");
			int index = bankno.indexOf("|");
			bankno = bankno.substring(0, index);
			//检查支付令
			if(check_payno(request.getParameter( "gx_corp_payno_tmp.payno"),bankno)!=0){
				//String s = "新增支付令出错，支付令重复";
				//throw(new SQLException(s));
				return -10;
			}
			mysql = "insert into gx_corp_payno_tmp(bankno,officeno,tellerno,payno,checkno,upd_date,upd_user,trans_seqno ) ";
			mysql += "values(\'" + bankno + "\',\'";
            mysql += request.getParameter( "gx_corp_payno_tmp.officeno") + "\',\'";
            mysql += request.getParameter( "gx_corp_payno_tmp.tellerno") + "\',\'";
            mysql += request.getParameter( "gx_corp_payno_tmp.payno") + "\',\'";
			mysql += request.getParameter( "gx_corp_payno_tmp.checkno") + "\',sysdate,'";
			mysql += m_user + "\'," ;
			gwkdb.query("select seq_trans.nextval from dual", 1);
			inseq = gwkdb.dbvt.get(0).get(0).toString();
			mysql += inseq + ")";
		}else if(m_op.compareTo("M") == 0){
			//修改
			mysql = "update gx_corp_payno_tmp ";
			mysql += "set officeno=\'" + request.getParameter("gx_corp_payno_tmp.officeno") + "\',";
			mysql += "tellerno=\'" + request.getParameter("gx_corp_payno_tmp.tellerno") + "\',";
            mysql += "payno=\'" + request.getParameter("gx_corp_payno_tmp.payno") + "\', ";
			mysql += "checkno=\'" + request.getParameter("gx_corp_payno_tmp.checkno") + "\', ";
			bankno = request.getParameter("gx_corp_payno_tmp.bankno");
			mysql += "bankno=\'" + bankno + "\', ";
			mysql += "upd_date=sysdate,";
			mysql += "upd_user=\'" + m_user + "\' ";
			inseq = request.getParameter("org_id");
			mysql += "where trans_seqno=\'" + inseq + "\'"; 
		}else if(m_op.compareTo("D") == 0){
			mysql = "delete from gx_corp_payno_tmp ";
			mysql += "where trans_seqno=\'" + vt.get(choice).get(7) + "\'"; 
		}else
			return -3;
		
		if(m_op.compareTo("Q") == 0){
			ret = gwkdb.query(mysql, 8);
		}else{
			ret = gwkdb.update(GwkDB.convert_chn(mysql));
		}
		if (ret < 0) {
			return ret;
		}
		
		if(m_op.compareTo("A")==0||m_op.compareTo("M")==0) {
			Vector<String> vt1 = new Vector<String>();
			vt1.add(bankno);
			vt1.add(request.getParameter("gx_corp_payno_tmp.officeno"));
			vt1.add(request.getParameter("gx_corp_payno_tmp.tellerno"));
            vt1.add(request.getParameter("gx_corp_payno_tmp.payno"));
			vt1.add(request.getParameter("gx_corp_payno_tmp.checkno"));
			vt1.add(m_user);
			vt1.add("");
			vt1.add(inseq);
			
			if(m_op.compareTo("A")==0){
				vt.add(vt1);
			}else{
				vt.set(choice, vt1);
			}
		}else if(m_op.compareTo("D")==0) {
			vt.remove(choice);
		}else{
			//操作成功
			vt.clear();
			vt = gwkdb.dbvt;
		}
		return 0;
	}

	private int do_pay_bill(int flag,HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException{
		String mysql = null;
		int ret;
		
		if (m_op == null) {
			// 空时
			return -1;
		} else if (m_op.compareTo("Q") == 0) {
			String pay_bill_info_id = request.getParameter("pay_bill_info_id");
			String sk_acct_no = request.getParameter("sk_acct_no");
			String organ_level_a = request.getParameter("organ_level_a");
			String unit_name = request.getParameter("unit_name");
			String upd_date = request.getParameter("upd_date");
			mysql = "select gx_corp_pay_bill_info.pay_bill_info_id, "
					+ " a.organ_level_a, a.unit_name, a.sk_acct_no,"
					+ " gx_corp_pay_bill_info.payee_sum_code, gx_corp_pay_bill_info.payee_sum_name, "
					+ " to_char(gx_corp_pay_bill_info.takeback_money,'99999999.99'), "
					+ " gx_corp_pay_bill_info.trans_seqno,to_char(gx_corp_pay_bill_info.upd_date,'yyyy/mm/dd')  "
					+ " from gx_corp_bank_unit a, gx_corp_pay_bill_info,gx_corp_cus "
					+ " where gx_corp_cus.organ_level_a = a.organ_level_a "
					+ " and gx_corp_pay_bill_info.payee_sum_code = gx_corp_cus.card_no"
					+ " and gx_corp_pay_bill_info.confirm = 'N'   ";
			if(pay_bill_info_id!=null && pay_bill_info_id.length()>0){
				mysql += "and gx_corp_pay_bill_info.pay_bill_info_id like '%" + pay_bill_info_id
						+ "%' ";
			}
			if(organ_level_a!=null && organ_level_a.length()>0){
				mysql += "and a.organ_level_a like '%" + organ_level_a	+ "%' ";
			}
			if(unit_name!=null && unit_name.length()>0){
				mysql += "and a.unit_name like '%" + unit_name
						+ "%' ";
			}
			if(sk_acct_no!=null && sk_acct_no.length()>0){
				mysql += "and a.sk_acct_no like '%" + sk_acct_no
						+ "%' ";
			}
			if(upd_date!=null && upd_date.length()>0){
				mysql += "and to_char(gx_corp_pay_bill_info.upd_date,'yyyymmdd') = '" + upd_date + "' ";
			}
			
			if(flag==1){
				mysql += "and gx_corp_pay_bill_info.pay_bill_info_id like 'ZSH%' ";
				// 机构号信息 begin
				mysql += " and a.ban_bank_no in (";
				for (int j = 0; j < vt_organ.size(); j++) {
					if (j == 0) {
						mysql += "'";
					} else
						mysql += ",'";
					mysql += vt_organ.get(j).get(0).toString() + "'";
				}
				mysql += ") ";
			}else{
				mysql += "and gx_corp_pay_bill_info.pay_bill_info_id not like 'ZSH%' ";
				mysql += "and gx_corp_pay_bill_info.upd_user='" + m_organ + "' ";
			}
		} else if (m_op.compareTo("A") == 0) {
			// 增加
		} else if (m_op.compareTo("M") == 0) {
			/*
			 * SET CONFIRM = 'Y', CONFIRM_DATE = :idt_date, CONFIRM_USER =
			 * :gs_uinfo.u_id, ORIG_CTR_DTM = :ld_orig_ctr_dtm, AB_FLAG = 'N'
			 */
			// 修改
			String[] cb = request.getParameterValues("cb");
			mysql = "update gx_corp_pay_bill_info ";
			mysql += "set confirm='Y',ab_flag='N',";
			mysql += "CONFIRM_USER='" + m_user + "',";
			mysql += "settle_time=sysdate ";
			mysql += "where trans_seqno in (";
			for(int i=0;i<cb.length;i++){
				if(i!=0)
					mysql += ",";
				mysql += vt.get(Integer.parseInt(cb[i])).get(7).toString();
			}
			mysql +=")";
		} else if (m_op.compareTo("D") == 0) {
			String[] cb = request.getParameterValues("cb");
			mysql = "delete from gx_corp_pay_bill_info ";
			mysql += "where trans_seqno in (";
			for(int i=0;i<cb.length;i++){
				if(i!=0)
					mysql += ",";
				mysql += vt.get(Integer.parseInt(cb[i])).get(7).toString();
			}
			mysql +=")";
		} else
			return -3;

		GwkDB gwkdb = new GwkDB();
		if (m_op.compareTo("Q") == 0)
			ret = gwkdb.query(mysql, 9);
		else
			ret = gwkdb.update(GwkDB.convert_chn(mysql));

		if (ret < 0) {
			return ret;
		}
		if(m_op.compareTo("D")==0||m_op.compareTo("M")==0) {
			String[] cb = request.getParameterValues("cb");
			for(int i=0;i<cb.length;i++){
				int j = Integer.parseInt(cb[i]);
				vt.remove(j-i);
			}
		}else{
			//操作成功
			vt.clear();
			vt = gwkdb.dbvt;
		}
		return 0;
	}
	
	/**   
	 * 此方法描述的是： 设置预制单位
	 * @author: 朱凯锋   
	 * @version: 2013年11月13日 下午2:41:25   
	 */
	private int do_bank_unit(HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException{
		String mysql = null;
		int choice = 0;
		int ret;

		// PrintWriter out = response.getWriter();
		if (request.getParameter("choice") != null) {
			choice = Integer.valueOf(request.getParameter("choice"));
		}

		if (m_op == null) {
			// 空时
			return -1;
		} else if (m_op.compareTo("Q") == 0) {
			String str_jigou = (String) request.getParameter("jigou");
			String str_dw_code = (String) request.getParameter("dw_code");
			String str_dw_name = (String) request.getParameter("dw_name");
			String str_sk_acct = (String) request.getParameter("sk_acct");
			String str_sk_bank = (String) request.getParameter("sk_bank");
			String str_sk_acct_name = (String) request.getParameter("sk_acct_name");
			mysql = "select ORGAN_LEVEL_A, unit_no, unit_name,ban_bank_no,sk_acct_no,sk_bank,sk_acct_name," +
					"INTERFACE_FLAG,upd_user, to_char(upd_date,'yyyy/mm/dd'),REGION_ID from GX_CORP_BANK_UNIT ";
			mysql += " where  ban_bank_no in (";
			for (int j = 0; j < vt_organ.size(); j++) {
				if (j == 0) {
					mysql += "'";
				} else
					mysql += ",'";
				mysql += vt_organ.get(j).get(0).toString() + "'";
			}
			mysql += ") ";
			if ((str_jigou != null) && (str_jigou.length() > 0)) {
				mysql += " and ORGAN_LEVEL_A like '%" + str_jigou + "%' ";
			}
			if ((str_dw_code != null) && (str_dw_code.length() > 0)) {
				mysql += " and unit_no like '%" + str_dw_code + "%' ";
			}
			if ((str_dw_name != null) && (str_dw_name.length() > 0)) {
				mysql += " and unit_name like '%" + str_dw_name + "%' ";
			}
			if ((str_sk_acct != null) && (str_sk_acct.length() > 0)) {
				mysql += " and sk_acct_no like '%" + str_sk_acct + "%' ";
			}
			if ((str_sk_bank != null) && (str_sk_bank.length() > 0)) {
				mysql += " and sk_bank like '%" + str_sk_bank + "%' ";
			}
			if ((str_sk_acct_name != null)
					&& (str_sk_acct_name.length() > 0)) {
				mysql += " and  sk_acct_name like '%" + str_sk_acct_name
						+ "%' ";
			}
			mysql += " order by upd_date desc ";
		} else if (m_op.compareTo("A") == 0) {
			// 增加
			mysql = "insert into GX_CORP_BANK_UNIT (BAN_BANK_NO, ORGAN_LEVEL_A, unit_no, " +
					"unit_name,sk_acct_no,sk_bank,sk_acct_name,INTERFACE_FLAG,REGION_ID,UPD_USER,upd_date) ";
			mysql += "values ( '" + request.getParameter("BAN_BANK_NO").toString() + "',";
			mysql += "'" + request.getParameter("ORGAN_LEVEL_A").toString() + "',";
			mysql += "'" + request.getParameter("UNIT_NO").toString() + "',";
			mysql += "'" + request.getParameter("UNIT_NAME").toString() + "',";
			mysql += "'" + request.getParameter("SK_ACCT_NO").toString() + "',";
			mysql += "'" + request.getParameter("SK_BANK").toString() + "',";
			mysql += "'" + request.getParameter("SK_ACCT_NAME").toString() + "',";
			mysql += "'" + request.getParameter("INTERFACE_FLAG").toString() + "',";
			mysql += "'" + request.getParameter("REGION_ID").toString() + "',";
			mysql += "'" + m_user + "',sysdate) ";
		} else if (m_op.compareTo("M") == 0) {
			// 修改
			mysql = "update GX_CORP_BANK_UNIT set ";
			mysql += "ORGAN_LEVEL_A='" + request.getParameter("ORGAN_LEVEL_A").toString() + "',";
			mysql += "UNIT_NO='" + request.getParameter("UNIT_NO").toString() + "',";
			mysql += "UNIT_NAME='" + request.getParameter("UNIT_NAME").toString() + "',";
			mysql += "SK_ACCT_NO='" + request.getParameter("SK_ACCT_NO").toString() + "',";
			mysql += "SK_BANK='" + request.getParameter("SK_BANK").toString() + "',";
			mysql += "SK_ACCT_NAME='" + request.getParameter("SK_ACCT_NAME").toString() + "',";
			mysql += "INTERFACE_FLAG=" + request.getParameter("INTERFACE_FLAG").toString() + ",";
			mysql += "BAN_BANK_NO='" + request.getParameter("BAN_BANK_NO").toString() + "',";
			mysql += "REGION_ID='" + request.getParameter("REGION_ID").toString() + "',";
			mysql += "upd_user='" + m_user + "',";
			mysql += "upd_date=sysdate ";
			mysql += "where ORGAN_LEVEL_A='"
					+ vt.get(choice).get(0).toString() + "'";
		} else if (m_op.compareTo("D") == 0) {
			mysql = "delete from GX_CORP_BANK_UNIT ";
			mysql += "where ORGAN_LEVEL_A='"
					+ vt.get(choice).get(0).toString();
			mysql += "' and UNIT_NO = '" +  vt.get(choice).get(1).toString() +"' ";
		} else
			return -3;

		GwkDB gwkdb = new GwkDB();
		if (m_op.compareTo("Q") == 0)
			ret = gwkdb.query(mysql, 11);
		else{
			try {
				ret = gwkdb.update(GwkDB.convert_chn(mysql));
			} catch (Exception e) {
				// TODO Auto-generated catch block
				ret = -1;
			}
		}

		if (ret < 0) {
			return ret;
		}
		if(m_op.compareTo("A")==0||m_op.compareTo("M")==0) {
			Vector<String> vt1 = new Vector<String>();
			vt1.add(request.getParameter("ORGAN_LEVEL_A"));
			vt1.add(request.getParameter("UNIT_NO"));
            vt1.add(GwkDB.convert_chn(request.getParameter("UNIT_NAME")));
            vt1.add(request.getParameter("BAN_BANK_NO"));
			vt1.add(GwkDB.convert_chn(request.getParameter("SK_ACCT_NO")));
			vt1.add(GwkDB.convert_chn(request.getParameter("SK_BANK")));
			vt1.add(GwkDB.convert_chn(request.getParameter("SK_ACCT_NAME")));
			vt1.add(request.getParameter("INTERFACE_FLAG"));
			vt1.add(m_user);
			vt1.add("-");
			vt1.add(request.getParameter("REGION_ID"));
			

			if(m_op.compareTo("A")==0){
				vt.add(0,vt1);
			}else{
				vt.set(choice, vt1);
			}
		}else if(m_op.compareTo("D")==0) {
			vt.remove(choice);
		}else{
			//操作成功
			vt.clear();
			vt = gwkdb.dbvt;
		}
		return 0;
	}
	/**   
	 * 此方法描述的是： 处理取还款明细
	 * @author: 朱凯锋   
	 * @version: 2013年11月24日 下午8:55:45   
	 * @throws IOException 
	 * @throws SQLException 
	 */
	private void do_payno(HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException{
		PrintWriter out = response.getWriter();
		GwkDB gwkdb = new GwkDB();
		//
		int ret = vt.size();
		if(ret==0){
			out.println("没有可操作的支付令!");
			return;
		}
		//去重复的bankno
		//System.out.println("vt.size 1:"+vt.size());
		for(int i=0;i<vt.size();i++){
			if((i+1)>=vt.size())
				break;
			for(int j=1;j<vt.size();j++){
				if(vt.get(i).get(0).toString().compareTo(vt.get(j).get(0).toString())==0){
					vt.remove(j);
					j--;
				}
			}
		}
		//System.out.println("vt.size 1:"+vt.size());
		
		//调用前台命令
		for(int i=0;i<vt.size();i++){
			//System.out.println(vt.size() + "@处理单位:" + vt.get(i).get(0).toString());
			//根据单位号，取相应接口，完成不同地方的取还款明细
			String mysql = "select a.ban_bank_no,a.interface_flag,b.bank_organ_level,"
					+ "b.bank_parent_id,a.region_id,a.unit_no  " 
					+"from gx_corp_bank_unit a,gx_corp_bank_organ b "
					+ "where a.organ_level_a = '" + vt.get(i).get(0).toString() +"' "
					+ "and a.ban_bank_no = b.bank_organ_id ";
			
			ret = gwkdb.query2(mysql, 6);
			if(ret <0){
				out.println("处理单位[" + vt.get(i).get(0).toString() + "]失败<br>");
				continue;
			}
			if(gwkdb.dbvt.size()==0){
				out.println("没有单位[" + vt.get(i).get(0).toString() + "]信息<br>");
				continue;
			}
			int iflag = Integer.parseInt(gwkdb.dbvt.get(0).get(1));
			if(iflag==0){
				//其它，不处理
				out.println("单位【<b style=\"color:red\">" + vt.get(i).get(0).toString() + "</b>】为接口类型为【其它】。"
					+ "需要操作取还款明细请重新设置该单位的基本资料<br>");
				continue;
			}else if(iflag==1){
				//区财政
				mysql = "/gwcard/bin/hkdet_n 00021 " + vt.get(i).get(0).toString() + " " + m_organ;
				out.println(GwkDB.convert_chn(GwkDB.callShell(mysql)));;
			}else if(iflag==2){
				//市财政
				//判断是否在市级机构 1
				int level = Integer.parseInt(gwkdb.dbvt.get(0).get(2));
				String sbankno = "";
				if(level==0){
					out.println("单位【<b style=\"color:red\">" + vt.get(i).get(0).toString() + "</b>】为所属机构为区行级。"
							+"请重新设置该单位的基本资料<br>");
					continue;
				}else if(level==1){
					sbankno = gwkdb.dbvt.get(0).get(0);
				}else if(level==2){
					//取父级
					sbankno = gwkdb.dbvt.get(0).get(3);
				}else{
					//级别3
					mysql = "select BANK_PARENT_ID from gx_corp_bank_organ "
						+ "where bank_organ_id = '" + gwkdb.dbvt.get(0).get(3) +"'";
					sbankno = gwkdb.dbvt.get(0).get(0);
				}
				//找出市级单位
				mysql = "/gwcard/bin/hkdet_n " +sbankno + " " + vt.get(i).get(0).toString() + " " + m_organ;
				out.println(GwkDB.convert_chn(GwkDB.callShell(mysql)));;
			}else if(iflag==3){
				//区县
				mysql = "/gwcard/bin/county_payno " + vt.get(i).get(0).toString()
					+ " " + gwkdb.dbvt.get(0).get(4) + " " + m_organ;
				out.println("<p>"+ mysql +"</p>");
				out.println(GwkDB.convert_chn(GwkDB.callShell(mysql)));;
			}else if(iflag==4){
				//南宁市财政
				mysql = "/gwcard/bin/qh_payno " + vt.get(i).get(0).toString()
					+ " " + gwkdb.dbvt.get(0).get(5).toString() + " " + m_organ;
				out.println("<p>"+ mysql +"</p>");
				out.println(GwkDB.convert_chn(GwkDB.callShell(mysql)));;
			}
		}
		vt.clear();
	}
	
	/**   
	 * 此方法描述的是： 支付令检查
	 * @author: 朱凯锋   
	 * @version: 2013年12月4日 下午5:15:44   
	 * @throws IOException 
	 * @throws SQLException 
	 */
	private int check_payno(String payno,String organ_level_a) throws SQLException, IOException {
		//是否已存在在tmp表
		String mysql = "select 1 from gx_corp_payno_tmp " +
				"where payno='" + payno + "' and bankno='" + organ_level_a + "' ";
		GwkDB gwkdb = new GwkDB();
		int ret = gwkdb.query(mysql, 1);
		if(ret <0)
			return ret;
		if(gwkdb.dbvt.size()>0)
			return -1;
		//是否存在paybill_info
		mysql = "select 1 from gx_corp_pay_bill_info a,gx_corp_cus b " +
				"where a.pay_bill_info_id='" + payno + "' and b.organ_level_a='" + 
				organ_level_a + "' and a.payee_sum_code = b.card_no";
		gwkdb.query(mysql, 1);
		if(gwkdb.dbvt.size()>0)
			return -1;
		
		return 0;
	}

}
